from django.db import models
from django import template
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.contrib.comments.signals import comment_was_posted
from pirate_issues.callbacks import update_issue_comment_count
#from ModuleDeliberation.models import Comment
from django.utils.translation import ugettext as _ 
from pirate_core.views import template_for_model
from pirate_forum.models import ForumBlob
from pirate_topics.models import Topic

#A specific issue of political concern. Are authors important?
#This should be a pirate-wikipage instance
class Problem(ForumBlob):

    class Meta:
        verbose_name = _('problem')

    def get_absolute_url(self):
        content_type = ContentType.objects.get_for_model(self.__class__)
        path = template_for_model(str(content_type)) + "?_t=" + str(content_type.pk) + "&_o=" + str(self.pk) 
        return path
    
    def get_verbose_name(self):
        return self._meta.verbose_name
    
    def is_root(self):
        return False
    
    def get_blob_key(self):
        return 'p'
    
    def get_child_blob_key(self):
        return 's'
    

class Solution(ForumBlob):
    
    class Meta:
        verbose_name = _('solution')

    def get_absolute_url(self):
        content_type = ContentType.objects.get_for_model(self.__class__)
        path = template_for_model(str(content_type)) + "?_t=" + str(content_type.pk) + "&_o=" + str(self.pk) 
        return path
    
    def get_verbose_name(self):
        return self._meta.verbose_name

    def is_root(self):
        return False
    
    def get_blob_key(self):
        return 's'
    
    
class Policy(ForumBlob):
    
    class Meta:
        verbose_name = _('policy')

    def get_absolute_url(self):
        content_type = ContentType.objects.get_for_model(self.__class__)
        path = template_for_model(str(content_type)) + "?_t=" + str(content_type.pk) + "&_o=" + str(self.pk) 
        return path
    
    def get_verbose_name(self):
        return self._meta.verbose_name

    def is_root(self):
        return False
    
    def get_blob_key(self):
        return 'l'
    

admin.site.register(Problem)
admin.site.register(Solution)
admin.site.register(Policy)

###SIGNALS
comment_was_posted.connect(update_issue_comment_count)

 
